package classes
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.utils.setTimeout;
	
	import mx.core.Application;
	
  [Bindable] public class Game	{
  	public static var score:int=0;
	public static var canStartGame:Boolean = false;
	public static var isOver:Boolean = false;
	public static var hasStarted:Boolean = false;
	public static var latency:Number = 0;
	public static var latencyTolerence:int = 2; // on envoit la donnée 2 * latency !
	
	public static var width:int = 800;
	public static var height:int = 600;
	public var timer:Timer = new Timer(10);
	private var numberBeforeStart:int = 3;
			
	public function Game()	{
		timer.addEventListener(TimerEvent.TIMER,incrementTimer);
	}
	private function incrementTimer(e:TimerEvent):void {
		Application.application.timerLabel.text = "Temps:"+timer.currentCount;
	}
	private function decrementStart():void {
		numberBeforeStart--;
		Application.application.info_txt.text="Start your engine:"+numberBeforeStart;
		if (numberBeforeStart==0) start() else setTimeout(decrementStart,1000);
	}
	public function prepareStart():void {
		numberBeforeStart = 3;
		setTimeout(decrementStart,1000);
	}
	public function start():void {
		Application.application.info_txt.text="Started";
		isOver = false;
		hasStarted = true;
		Application.application.initKeyBoard();
		timer.start();
	}
	
	public function over(message:String):void {		
		Application.application.info_txt.text="Game Over : "+message;
		isOver = true;
		hasStarted = false;
		Application.application.removeKeyBoard();
		timer.stop();
	
	}		

  }
}